<template>
    <div>
        <Row class="list_row" style="margin-top: 0px">
            <Row style="margin: 5px 0px 10px 0px">
                <Input v-model="searchKeyword" :placeholder="$t('courseP.coursePlaceTips')" style="width: 200px; margin-right: 20px" />
                <Button class="btnWhite" type="primary" icon="ios-search" style="margin-right: 20px" @click="search">{{$t('search')}}</Button >
                <Button class="btnWhite" type="primary" icon="md-add" @click="showAddModal" v-if="roleId == '4'" >{{$t('courseP.addCourseBtn')}}</Button>
            </Row>
    
        <Table  :columns="planColumn" border :data="dataList" stripe  :no-data-text="noDataMsg">

                        <template slot-scope="{ row, index }" slot="seq">
    
                          {{ (currentPage - 1) * pageSize + index + 1 }}
                       </template>
      </Table>
      <div class="div_page">
        <Page
          :total="totalCount"
          :current="currentPage"
          :page-size="pageSize"
          show-total
          show-elevator
          prev-text="<"
          next-text=">"
          @on-change="pageChg"
        />
      </div>
    </Row>
    <Modal
    :title="$t('courseP.courseDiyTips')"
  v-model="dIyVisiable"
  width="350"
  :mask-closable="false">
  <Input  
         v-model="trainActionNameTemp"
              
                    />
                    <div slot="footer" style="text-align: center">
        <Button @click="getActionNameHandle">{{$t('yes')}}</Button>
                    </div>
</Modal>

    <!-- 新增课程弹窗 -->
    <Modal
  
      v-model="entityModelVisiable"
      :mask-closable="false"
      width="1300"
      :title="entityModelTitle"
      :styles="{ top: '20px' }"
    >
      <Form
        ref="entityFormRef"
        :model="entityForm"
        :rules="addFormRules"
        :label-width="80"
      >
        <div style="padding: 0px 18px">
          <FormItem :label="$t('common.courseName')" prop="name">
            <Input
              v-model="entityForm.name"
            :placeholder="$t('courseP.coursePlaceTips')"
              style="width: 400px"
              :disabled="entityForm.opeType === 'view'"
            ></Input>
          </FormItem>
        </div>
        <div :style="collapseStyle">
          <Collapse
            v-model="entityForm.trainDetailCollapse"
            accordion
            style="margin-top: 24px"
          >
            <Panel
              :name="detail.uuid"
              v-for="(detail,index) in entityForm.detailList"
              :key="detail.uuid"
            >
              {{$t('courseP.courseInfo')}}{{ detail.seq }}
              <div style="float: right; margin-right: 20px">
                <Button
                  type="error"
                  size="small"
                  @click.stop="deleteDetail(detail.uuid)"
                  v-show="entityForm.opeType != 'view'"
                  >{{$t('common.deleteBtn')}}
                </Button>
              </div>
              <div slot="content">
                <FormItem :label="$t('courseP.courseCatory')" class="inner_form_item wrapSelect">
                  <span class="actionName" v-if=" +detail.trainActionId==16 ">{{detail.trainActionName}}</span>
                  <Select
                    v-model="detail.trainActionId"
                    :placeholder="$t('courseP.courseCatoryTips')"
                    label-in-value
                  @on-select="handleChange($event,detail.trainActionName,index)"

                    :disabled="entityForm.opeType === 'view'"
                    style="width: 283px; margin-right: 20px"
                  >
                    <Option
                      v-for="action in trainActionList"
                      :value="action.id"
                      :key="action.id"
                      >{{ action.name }}
                    </Option>
                  </Select>
                  <Button
                    type="info"
                    ghost
                    icon="md-add"
                    @click.stop="addPlanDetailGroup(detail.uuid)"
                    v-show="entityForm.opeType != 'view'"
                    >{{$t('courseP.courseCt')}}
                  </Button>
                </FormItem>
                <Divider orientation="left">{{$t('courseP.courseCt')}}</Divider>
                <Table
                  :columns="planDetailGroupColumn"
                  border
                  :data="detail.groupList"
                  stripe
                  :no-data-text="noDataMsg"
                >
                    <template slot-scope="{ row, index }" slot="seq">
                        {{ (currentPage - 1) * pageSize + index + 1 }}
                    </template>
                    <template slot-scope="{ row, index }" slot="rate">
                        <Input v-model="detail.groupList[index].rate" type="number" :placeholder="$t('courseP.gSpeedPlaceTips')" @on-blur="handleBlurRate($event,detail.groupList[index],row)" :disabled="entityForm.opeType === 'view'">
                        </Input>
                    </template>
                    <template slot-scope="{ row, index }" slot="power">
                        {{ detail.groupList[index].power }}
                    </template>
                    <template slot-scope="{ row, index }" slot="work">
                        <Input v-model="detail.groupList[index].work" type="number" :placeholder="$t('courseP.powerPlaceTips') " :disabled="entityForm.opeType == 'view'">
                        </Input>
                    </template>
                    <template slot-scope="{ row, index }" slot="weight">
                        <Input v-model="detail.groupList[index].weight" type="number" :placeholder="$t('courseP.weightPlaceTips') " @on-blur="handleBlurWeight($event,detail.groupList[index],row)" :disabled="entityForm.opeType == 'view'">
                        </Input>
                    </template>
                    <template slot-scope="{ row, index }" slot="frequency">
                        <Input v-model="detail.groupList[index].frequency" type="number" :placeholder="$t('courseP.timePlaceTips')"  :disabled="entityForm.opeType == 'view'">
                        </Input>
                    </template>
                    <template slot-scope="{ row, index }" slot="breakTime">
                        <Input v-model="detail.groupList[index].breakTime" type="number" :placeholder="$t('courseP.weakPlaceTips')"   :disabled="entityForm.opeType == 'view'">
                        </Input>
                    </template>
                    <template slot-scope="{ row, index }" slot="action">
                        <Icon type="ios-remove-circle-outline" size="26" color="red" @click="deleteDetailGroup(detail.uuid, row.uuid)" v-show="entityForm.opeType != 'view'" />
                    </template>
                </Table>
              </div>
            </Panel>
          </Collapse>
        </div>
      </Form>
      <Button
        type="warning"
        ghost
        icon="md-add"
        style="width: 100%; margin-top: 15px"
        @click="addPlanDetail()"
        v-show="entityForm.opeType != 'view'"
        >{{$t('courseP.courseXq')}}
      </Button>
      <div slot="footer" style="text-align: center">
        <Button @click="entityModelVisiable = false">{{$t('cancel')}}</Button>
        <Button
          type="primary"
          @click="saveOrUpdate"
          :loading="saveLoading"
          style="margin-left: 15px"
          v-show="entityForm.opeType != 'view'"
        >
          <span v-if="!saveLoading">{{$t('save')}}</span>
          <span v-else>{{$t('save')}}....</span>
        </Button>
      </div>
    </Modal>
  </div>
</template>
<script>
import CommonApi from "@/api/commonApi";
import CourseApi from "@/api/courseApi";
import TrainCenterApi from "@/api/trainCenterApi";
import { isEmpty, copyObj, genUuid } from "@/libs/util";
import { mapGetters } from "vuex";

export default {
    data() {
        return {
            trainActionIndex: 0,
            trainActionNameTemp: '',
            dIyVisiable: false,
            isChoose: true,
            roleId: "",
            planDetailSpinShow: false,
            trainActionList: [],
            saveLoading: false,
            searchKeyword: "",
            noDataMsg: this.$t('common.noData'),
            entityModelTitle: this.$t('courseP.addCourseBtn'),
            isCanChooseTc: false,
            trainCenterList: [],
            entityModelVisiable: false,
            entityForm: {},
            weightUnit: 'kg',
            addFormRules: {
                name: [
                    { required: true, message: this.$t('courseP.courseMustTips') , trigger: "blur" },
                    {
                        type: "string",
                        max: 32,
                        message: this.$t('common.namelenLow32Tips'), 
                        trigger: "blur",
                    },
                ],
            },
            planDetailArr: [],
            totalCount: 20,
            currentPage: 1,
            pageSize: 10,
            dataList: [],
            collapseStyle: {
                height: "200px",
                overflowY: "auto",
            },
            planDetailGroupColumn: [{
                title: this.$t('common.seq'), 
          slot: "seq",
          width: '110',
                },
                {
                    title: this.$t('courseP.targetScore')+"(m/s)",
                    slot: "rate",
                },
                {
                    title:  this.$t('courseP.targetW')+"（J）",
                    slot: "work",
                },
                {
                    title: this.$t('courseP.targetP')+ "（W）",
                    width: '160',
                    slot: "power",
                },
                {
                    title:this.$t('common.heft') +'(kg)',
                    width: '180',
                    slot: "weight",
                    renderHeader: (h, params) => {
                        return h('span', [
                            h('span',this.$t('common.heft') + `（${this.weightUnit}）`),
                            h('Button', {
                                props: {
                                    type: "info",
                                    size: "small",
                                },
                                on: {
                                    click: () => {

                                        this.transUnit()


                                    },
                                },
                            }, this.$t('courseP.change')),
                        ])

                    },
                },

                {
                    title:  this.$t('courseP.times'),
                    slot: "frequency",
                },
                {
                    title: this.$t('courseP.breakTime'),
                    slot: "breakTime",
                },
                // {
                //   title: this.$t('common.optColumn') ,
                //     slot: "action",
                //     width: 57,
                // },
            ],
            planColumn: [{
                   title: this.$t('common.seq'), 
          slot: "seq",
          width: '110',
                    render: (h, params) => {
                        return h(
                            "span", {
                                class: "sortBlock",
                            },
                            params.index + 1
                        );
                    },
                },
                {
                   title: this.$t('common.courseName'), 
                    key: "name",
                },
                {
                   title: this.$t('common.creator'), 
                    key: "createUserName",
                },
                {
                   title: this.$t('common.createTime'), 
                    key: "createTime",
                },
                {
                   title: this.$t('common.updateTime'), 
                    key: "updateTime",
                },
                {
                    title: this.$t('common.optColumn') ,
                    key: "action",
                    width:220,
                    render: (h, params) => {
                        return h("div", [
                            h(
                                "Button", {
                                    props: {
                                        type: "info",
                                        size: "small",
                                    },
                                    style: {
                                        marginRight: "15px",
                                    },
                                    class: "btnBlue",
                                    on: {
                                        click: () => {
                                            this.showViewModal(params.row);
                                        },
                                    },
                                },
                                 this.$t('common.previewBtn') 
                            ),
                            h(
                                "Button", {
                                    props: {
                                        type: "warning",
                                        size: "small",
                                    },
                                    style: {
                                        marginRight: "15px",
                                        display: params.row.canModify ? "inline" : "none",
                                    },
                                    class: "btnYellow",
                                    on: {
                                        click: () => {
                                            this.showEditModal(params.row);
                                        },
                                    },
                                },
                               this.$t('common.editBtn') 
                            ),
                            h(
                                "Button", {
                                    props: {
                                        type: "error",
                                        size: "small",
                                    },
                                    style: {
                                        display: params.row.canModify ? "inline" : "none",
                                    },
                                    class: "btnRed",
                                    on: {
                                        click: () => {
                                            this.del(params.row);
                                        },
                                    },
                                },
                              this.$t('common.deleteBtn') 
                            ),
                        ]);
                    },
                },
            ],
        };
    },
    created() {
        this.roleId = this.getRoleId();
        this.search();
        this.initTrainAction();
        // 计算屏幕高度
        var clientH =
            document.documentElement.clientHeight || document.body.clientHeight;
        clientH = clientH - 270;
        this.collapseStyle = {
            height: clientH + "px",
            overflowY: "auto",
        };
    },
    watch: {
        weightUnit: {
            handler(val) {
                if (JSON.stringify(this.entityForm) !== "{}") {

                    this.entityForm.detailList.map((i, index) => {
                        i.groupList.map((ii, kk) => {
                            if (this.weightUnit == "lb") {
                                ii.weight = ii.weight * 2.205

                            } else {

                                ii.weight = ii.weight / 2.205
                            }
                            ii.weight = this.isTofixed2(ii.weight)

                        })

                    })
                }
            },
            immediate: true
        }
    },
    methods: {
        ...mapGetters(["getRoleId"]),
        getActionNameHandle() {
          
            if(this.trainActionNameTemp==""){
                this.$Message.error(this.$t('courseP.nameMust'));
             return 
            }
            this.dIyVisiable = false
            this.entityForm.detailList.forEach((i, index1) => {
                if (index1 === this.trainActionIndex) {
                    i.trainActionName = this.trainActionNameTemp
                }})
         
        },
        trangeData() {

        },
        // 默认课程详情中的组
        handleBlurWeight(e, item, row) {
            if (this.weightUnit == "lb") {
                item.power = e.target._value * row.rate / 2.205
            } else {
                item.power = e.target._value * row.rate
            }
            item.power = this.isTofixed2(item.power)
        },
        handleBlurRate(e, item, row) {
            if (this.weightUnit == "lb") {
                item.power = e.target._value * row.weight / 2.205
            } else {
                item.power = e.target._value * row.rate
            }
            item.power = this.isTofixed2(item.power)

        },
        transUnit() {

            if (this.weightUnit == "kg") {
                this.weightUnit = "lb"
            } else if (this.weightUnit == "lb") {
                this.weightUnit = "kg"
            }


        },
        isTofixed2(v) {
            const posIntReg = /^[1-9]\d*$/;
            if (!posIntReg.test(v)) {
                v = v.toFixed(2)
                console.log("不是整数", v)
                return v
            } else {
                return v
            }
        },
        getDefPlanDetailGroup(seq) {
            seq = seq || 1;
            let weight = 20,
                rate = 0.5,
                power = 0;

            if (this.weightUnit == "lb") {
                weight = weight * 2.205
                power = weight * rate / 2.205;
            } else {
                power = weight * rate;
            }
            power = this.isTofixed2(power)
            weight = this.isTofixed2(weight)
            return {
                uuid: genUuid(),
                seq: seq,
                rate,
                weight,
                work: 500,
                power,
                frequency: 10,
                breakTime: 5,
            };
        },
        // 默认课程详情
        getDefPlanDetail(seq) {
            seq = seq || 1;
            var detail = {
                uuid: genUuid(),
                seq: seq,
                trainActionId: 1,
                groupList: [],
            };
            detail.groupList.push(this.getDefPlanDetailGroup());
            return detail;
        },
        findPlanDetail(uuid) {
            const detailList = this.entityForm.detailList;
            var currentDetail = null;
            for (var i = 0; i < detailList.length; i++) {
                var detail = detailList[i];
                if (detail.uuid == uuid) {
                    currentDetail = detail;
                    break;
                }
            }
            return currentDetail;
        },
        deleteDetail(uuid) {
            const detailList = this.entityForm.detailList;
            if (detailList.length == 1) {
                this.$Message.error(this.$t('courseP.oneCtips'));
                return;
            }
            var removeIndex;
            for (var i = 0; i < detailList.length; i++) {
                var detail = detailList[i];
                if (detail.uuid == uuid) {
                    removeIndex = i;
                    break;
                }
            }
            detailList.splice(removeIndex, 1);
            // 重新排序
            for (var i = 0; i < detailList.length; i++) {
                var detail = detailList[i];
                detail.seq = i + 1;
            }
        },
        deleteDetailGroup(detailUuid, groupUuid) {
            var currentDetail = this.findPlanDetail(detailUuid);
            var groupList = currentDetail["groupList"];
            if (groupList.length == 1) {
                this.$Message.error(this.$t('courseP.oneGtips'));
                return;
            }
            var removeIndex;
            for (var i = 0; i < groupList.length; i++) {
                var group = groupList[i];
                if (group.uuid == groupUuid) {
                    removeIndex = i;
                    break;
                }
            }
            groupList.splice(removeIndex, 1);
            // 重新排序
            for (var i = 0; i < groupList.length; i++) {
                var group = groupList[i];
                group.seq = i + 1;
            }
        },
        addPlanDetail() {
            const detailList = this.entityForm.detailList;
            var planDetail = this.getDefPlanDetail(detailList.length + 1);

            detailList.push(planDetail);
        },
        addPlanDetailGroup(uuid) {

            var currentDetail = this.findPlanDetail(uuid);
            var groupList = currentDetail["groupList"];
            var defaultGroup = this.getDefPlanDetailGroup(groupList.length + 1);

            groupList.push(defaultGroup);
            for (var i = 0; i < groupList.length; i++) {
                var group = groupList[i];
                group.seq = i + 1;
            }
        },
        initTrainAction() {
            CommonApi.getAllTrainAction().then(
                (res) => {
                    const data = res.data.data;
                    this.trainActionList = data.actions;
                    if (this.$i18n.locale === "en-US") {
                        this.trainActionList = data.actions.map((i)=>{
                       return  {
                            id:i.id,
                            name:i.enName
                        }
                        } )
                    }

                },
                (error) => {
                    this.$Message.error(error.response.data.msg);
                }
            );
        },
        handleChange(e, syncActiom, index) {

            if (+e.value == 16) {
                this.dIyVisiable = true;
             
                    this.trainActionNameTemp=""
                this.trainActionIndex = index;
                this.entityForm.detailList.forEach((i, index1) => {
                if (index1 === this.trainActionIndex) {
                    i.trainActionName = this.trainActionNameTemp
                }
            })

            }else{
                this.trainActionNameTemp=""
             
            }

        },
        // handleChangeQuery(val){

        //   this.isChoose=true;
        // },
        // handleCreate(val) {

        // //  this.isChoose=true;
        //   this.trainActionList.push({
        //     id:val,
        //     name: val,
        //   });

        // },
        searchTrainCenter(keyword) {
            var param = { pageSize: 10, currentPage: 1 };
            if (keyword.length > 0) {
                param.name = keyword;
            }
            TrainCenterApi.pageResult(param).then(
                (res) => {
                    this.trainCenterList = res.data.data.pageResult.items;
                },
                (error) => {
                    this.$Message.error(error.response.data.msg);
                }
            );
        },
        search() {
            this.currentPage = 1;
            this.fetchDataList();
        },
        fetchDataList() {
            this.noDataMsg =this.$t('common.loading');
            this.dataList = [];
            var param = {
                pageSize: this.pageSize,
                currentPage: this.currentPage,
                sourceType: 1,
            };
            if (this.searchKeyword.length > 0) {
                param.name = this.searchKeyword;
            }
            CourseApi.pageResult(param).then(
                (res) => {
                    this.dataList = res.data.data.pageResult.items;
                    this.totalCount = res.data.data.pageResult.totalCount;
                    this.noDataMsg = this.$t('common.noData');
                },
                (error) => {
                    this.$Message.error(error.response.data.msg);
                }
            );
        },
        playVideo(id) {
            const routeData = this.$router.resolve({
                name: "video",
                query: { id: id },
                // query: params,
                // params: {catId: params.catId}
            });
            window.open(routeData.href, "_blank");
        },
        viewAnalysis(id) {
            const routeData = this.$router.resolve({
                name: "report",
                query: { id: id },
                // query: params,
                // params: {catId: params.catId}
            });
            window.open(routeData.href, "_blank");
        },
        showAddModal() {
            this.$refs.entityFormRef.resetFields();
            this.entityForm = {
                id: "",
                name: "",
                trainDetailCollapse: "",
                sourceType: 1,
                detailList: [],
                opeType: "add",
            };
            const detail = this.getDefPlanDetail();
            this.entityForm.detailList.push(detail);
            this.entityModelTitle = this.$t('courseP.addCourseBtn');
            this.entityModelVisiable = true;
            this.isChoose = true;
            // 默认展开第一个
            this.entityForm.trainDetailCollapse = detail.uuid;
        },
        showViewModal(row) {
            this.$refs.entityFormRef.resetFields();
            this.entityModelVisiable = true;
            this.entityModelTitle = this.$t('courseP.lookCourse');
            // this.$Spin.show()
            CourseApi.get(row.id).then(
                (response) => {
                    // this.$Spin.hide()
                    this.entityForm = response.data.data.course;
                    this.entityForm.opeType = "view";
                    this.isChoose = false;
                    if (JSON.stringify(this.entityForm) !== "{}") {

                        this.entityForm.detailList.map((i, index) => {
                            i.groupList.map((ii, kk) => {
                                if (this.weightUnit == "lb") {
                                    ii.weight = ii.weight * 2.205
                                    ii.weight = this.isTofixed2(ii.weight)
                                }

                            })

                        })
                    }
                    if (this.entityForm.detailList.length > 0) {
                        const detail = this.entityForm.detailList[0];
                        this.entityForm.trainDetailCollapse = detail.uuid;
                    }
                },
                (error) => {
                    this.saveLoading = false;
                    this.$Message.error(error.response.data.msg);
                }
            );
        },
        showEditModal(row) {
            this.$refs.entityFormRef.resetFields();
            this.entityModelVisiable = true;
            this.entityModelTitle = this.$t('courseP.editBtn');


            // this.$Spin.show()
            CourseApi.get(row.id).then(
                (response) => {
                    // this.$Spin.hide()
                    this.entityForm = response.data.data.course;
                    if (JSON.stringify(this.entityForm) !== "{}") {

                        this.entityForm.detailList.map((i, index) => {
                            i.groupList.map((ii, kk) => {
                                if (this.weightUnit == "lb") {
                                    ii.weight = ii.weight * 2.205
                                    ii.weight = this.isTofixed2(ii.weight)
                                }

                            })

                        })
                    }
                    this.entityForm.opeType = "edit";
                    this.isChoose = false;
                    if (this.entityForm.detailList.length > 0) {
                        const detail = this.entityForm.detailList[0];
                        this.entityForm.trainDetailCollapse = detail.uuid;
                    }
                },
                (error) => {
                    this.saveLoading = false;
                    this.$Message.error(error.response.data.msg);
                }
            );
        },
        saveOrUpdate() {
     
            this.$refs.entityFormRef.validate((valid) => {

                if (valid) {
                    // 校验详情里 重量/次数/分钟都必须是整数
                    var errMsg = "";
                    for (var i = 0; i < this.entityForm.detailList.length; i++) {
                        var detail = this.entityForm.detailList[i];
                        errMsg = this.varlidateDetail(detail, i + 1);
                        if (errMsg.length > 0) {
                            break;
                        }
                    }
                    if (errMsg.length > 0) {
                        this.$Message.error(errMsg);
                        return;
                    }
                    this.saveLoading = true;
                    let postForm = this.entityForm
                    postForm.detailList.map((i, index) => {
                        i.groupList.map((ii, kk) => {
                            if (this.weightUnit == "lb") {
                                ii.weight = ii.weight / 2.205
                                ii.power = ii.weight * ii.rate
                                ii.weight = this.isTofixed2(ii.weight)
                                ii.power = this.isTofixed2(ii.power)
                            }
                        })
                    })

                    CourseApi.saveOrUpdate(postForm).then(
                        (response) => {
                            this.saveLoading = false;
                            if (this.entityForm.id == "") {
                                this.$Message.success(this.$t('common.addSuc'));
                            } else {
                                this.$Message.success(this.$t('common.editSuc'));
                            }

                            this.$refs.entityFormRef.resetFields();
                            this.entityModelVisiable = false;
                            this.fetchDataList();
                        },
                        (error) => {
                            this.saveLoading = false;
                            this.$Message.error(error.response.data.msg);
                        }
                    );
                }
            });
        },
        varlidateDetail(detail, detailIndex) {

            console.log("进入校验：" + detailIndex);
            if(+detail.trainActionId==16 && detail.trainActionName=="" ){
                if(this.$i18n.locale === "zh-CN"){
  return (
                        "课程详情" +
                        detailIndex +
                        "的【自定义】训练种类名称不能为空"
                    );
                }else{
                     return 'The custom training type name for course detail '+detailIndex+' cannot be empty'
         
                }
              
            }
            const groupList = detail.groupList;
            for (var i = 0; i < groupList.length; i++) {
                var group = groupList[i];
                if (+group.rate <= 0) {
                    if(this.$i18n.locale === "zh-CN"){
                    return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【速度】不能小于等于0"
                    );
                    }else{
                        return 'The speed in '+(i + 1)+' training content of the course details '+detailIndex+'cannot be less than or equal to 0'
                    }
                }
                if (+group.work <= 0) {
                  if(this.$i18n.locale === "zh-CN"){
 return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【做功】不能小于等于0"
                    );
                    }else{
                        return 'Course detail '+detailIndex+': In the '+ (i + 1)+' training content, [Work] cannot be less than or equal to 0'
                    }
                   
                }
                if (+group.power <= 0) {
                     if(this.$i18n.locale === "zh-CN"){
 return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【功率】不能小于等于0"
                    );
                     }else{
return 'In the '+detailIndex+' training content of course detail ' (i + 1) +', the power cannot be less than or equal to 0'
                     }
                   
                }
                if (+group.weight <= 0) {
                        if(this.$i18n.locale === "zh-CN"){
 return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【重量】不能小于等于0"
                    );
                        }else{
return 'In the '+detailIndex+' training content of course detail ' (i + 1) +', the weight cannot be less than or equal to 0'
                        }
                   
                }
                const floadReg =
                    /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
                if (!floadReg.test(group.rate)) {
                       if(this.$i18n.locale === "zh-CN"){
return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【速度】最多只能保留两位小数位"
                    );
                       }else{
return 'Course detail '+detailIndex+': In the  '+(i + 1) +' training content, the speed cannot be less than or equal to 0, and can only retain a maximum of two decimal places'
                       }
                    
                }
                // 整数
                const posIntReg = /^[1-9]\d*$/;
                if (!floadReg.test(group.weight)) {
                      if(this.$i18n.locale === "zh-CN"){
                          return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【重量】最多保留两位小数位"
                    )
                      }else{
 return 'In the '+(i + 1) +' training content of course detail '+detailIndex+', the weight cannot be less than or equal to 0, and can only retain a maximum of two decimal places'
                      }
                  
                   
                }
                if (!posIntReg.test(group.frequency)) {
                      if(this.$i18n.locale === "zh-CN"){
 return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【次数】必须为正整数"
                    );
                      }else{
return 'The number of times in the '+(i + 1) +' training content of course detail '+detailIndex+' must be a positive integer'
                      }
                   
                }
                if (!posIntReg.test(group.breakTime)) {
                     if(this.$i18n.locale === "zh-CN"){
    return (
                        "课程详情" +
                        detailIndex +
                        "第 " +
                        (i + 1) +
                        "个训练内容中【组间休息时间】必须为正整数"
                    );
                     }else{
return 'Course detail '+detailIndex+': In the '+(i + 1) +' training content, the inter group rest time must be a positive integer'
                     }
                
                }
            }
            return "";
        },
        pageChg(selPage) {
            this.currentPage = selPage;
            this.fetchDataList();
        },
        del(row) {
            this.$Modal.confirm({
               title: this.$t('common.dDeleteTitleConfirm'),
        content: this.$t('common.DdeleteCt'),
        okText: this.$t('common.deleteBtn'),
        cancelText: this.$t('cancel'),
                onOk: () => {
                    this.doDel(row.id);
                },
            });
        },
        doDel(id) {
            CourseApi.delete(id).then(
                (res) => {
                 this.$Message.success(this.$t('common.deleteSuc'))
                    this.fetchDataList();
                },
                (error) => {
                    this.$Message.error(error.response.data.msg);
                }
            );
        },
        /*     speedChange(e, index) {
          console.log(
            e.target._value,
            "eee",
            this.entityForm.detailList[index].weight
          );
          this.entityForm.detailList[index].power =
            e.target._value * this.entityForm.detailList[index].weight;
          console.log(this.entityForm.detailList[index].power, "pow");
        },
        weightChange(e, index) {
          this.entityForm.detailList[index].power =
            e.target._value * this.entityForm.detailList[index].rate;
          console.log(this.entityForm.detailList[index].power, "pow");
        }, */
    },
};
</script>
<style scoped>
.detailSpan {
    display: inline-block;
    margin: 0px 10px;
    font-size: 16px;
    line-height: 32px;
}

.detail_icon {
    cursor: pointer;
}

.ivu-form-item {
    margin-bottom: 10px;
}

.ivu-divider-horizontal.ivu-divider-with-text-center,
.ivu-divider-horizontal.ivu-divider-with-text-left,
.ivu-divider-horizontal.ivu-divider-with-text-right {
    font-weight: 500;
    color: #888;
    font-size: 13px;
    margin: 20px 0 10px 0;
}

.ivu-icon:hover {
    opacity: 0.4;
    cursor: pointer;
}

.ivu-form-item-content {
    position: relative;
}

.actionName {
    display: inline-block;
    position: absolute;
    left: 60px;
    z-index: 10;
    top: 1px;
    font-size: 14px;
}

.inputBox {
    display: inline-block;
    position: absolute;
    left: 60px;
    z-index: 10;
    top: 1px;
    width: 223px;
}
</style>
